//
//  ByBlueToothMeaturesS4Model.m
//  laserdevice_ios
//
//  Created by pro on 16/12/12.
//  Copyright © 2016年 com.itboye. All rights reserved.
//

#import "ByBlueToothMeaturesH2Model.h"

@implementation ByBlueToothMeaturesH2Model

- (instancetype)initWithDataHexString:(NSString *)hexStr {
    
    if (self = [super initWithDataHexString:hexStr]) {
        
        self.name = [NSString stringWithFormat:@"H2%@", STRING(@"moxing")];

        NSString *angleStr = [hexStr substringWithRange:NSMakeRange(42, 18)];
        self.angle = [[self getNumberFromHexStr:angleStr] floatValue];
        NSString *lengthStr1 = [hexStr substringWithRange:NSMakeRange(70, 18)];
        self.hypotenuseLength = [[self getNumberFromHexStr:lengthStr1] floatValue];
        NSString *lengthStr2 = [hexStr substringWithRange:NSMakeRange(98, 18)];
        self.horizontalLength = [[self getNumberFromHexStr:lengthStr2] floatValue];
        NSString *lengthStr3 = [hexStr substringWithRange:NSMakeRange(126, 18)];
        self.verticalLength = [[self getNumberFromHexStr:lengthStr3] floatValue];
        
        NSLog(@"%li,%.2f,%.2f,%.2f,%.2f", self.numOfData, self.hypotenuseLength, self.horizontalLength, self.verticalLength, self.angle);
    }
    return self;
}

- (instancetype)initWithJsonDic:(NSDictionary *)jsonDic {
    
    if (self = [super initWithJsonDic:jsonDic]) {
        
        NSArray *attributes = jsonDic[@"attributes"];
        self.angle = [attributes[0] floatValue];
        self.hypotenuseLength = [attributes[1] floatValue];
        self.horizontalLength = [attributes[2] floatValue];
        self.verticalLength = [attributes[3] floatValue];
    }
    return self;
}


- (NSDictionary *)saveDic {
    
    NSArray *attributes = @[[NSString stringWithFormat:@"%.3lf", self.angle],
                            [NSString stringWithFormat:@"%.6lf", self.hypotenuseLength],
                            [NSString stringWithFormat:@"%.6lf", self.horizontalLength],
                            [NSString stringWithFormat:@"%.6lf", self.verticalLength],];
    return @{@"name"        :self.name,
             @"attributes"  :attributes,};
}

- (NSString *)angleStr {
    
    return [NSString stringWithFormat:@"%.1f", self.angle];
}
- (NSString *)hypotenuseLengthStr {
    
    return [self getStringFromLength:self.hypotenuseLength];
}
- (NSString *)horizontalLengthStr {
    
    return [self getStringFromLength:self.horizontalLength];
}
- (NSString *)verticalLengthStr {
    
    return [self getStringFromLength:self.verticalLength];
}

@end
